package logic

import (
	"apple/models/mysql"
	"context"

	"apple/applerpc/applerpc"
	"apple/applerpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ThumbsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewThumbsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ThumbsLogic {
	return &ThumbsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 点赞
func (l *ThumbsLogic) Thumbs(in *applerpc.ThumbsRequest) (*applerpc.ThumbsResponse, error) {
	// todo: add your logic here and delete this line
	var activity mysql.Activity
	mysql.DB.Debug().Where("id=?", in.Id).Find(&activity)

	activity.Thumbs = activity.Thumbs + 1
	mysql.DB.Debug().Updates(&activity)
	return &applerpc.ThumbsResponse{
		Image:     activity.Image,
		Name:      activity.Name,
		Publisher: activity.Publisher,
		Class:     activity.Class,
		Message:   activity.Message,
		UserId:    activity.UserId,
		Thumbs:    activity.Thumbs,
	}, nil
}
